<!-- 用信管理--还款明细 -->
<template>
  <div>
    <PlusPage
      :columns="pageConfig"
      :table="{
        adaptive: true,
        hasIndexColumn: true,
        actionBar: { buttons, width: 140 },
      }"
      :default-page-info="{ pageSize: DEFAULT_PAGE_SIZE, page: 1 }"
      :request="getList"
    />
  </div>
</template>

<script lang="ts" setup>
import type { PageInfo, PlusColumn } from '@wlydfe/pro-ui'
import type { BasePageReq } from '@wlydfe/service'
import type { RepaymentModel } from '@/api/type'
import { priceToThousands } from '@wlydfe/core'
import { useTable } from '@wlydfe/pro-ui'
import { omit } from 'lodash-es'
import { creditmanageApi } from '@/api'
import { useEnum } from '@/composables/enum/useEnum'

const enumConfig = useEnum([CommonDictEnum.YDDHKLX])

const DEFAULT_PAGE_SIZE = 20
const queryParams = ref<BasePageReq<Partial<RepaymentModel>>>({
  currentPage: 1,
  pageLength: DEFAULT_PAGE_SIZE,
  countTotal: true,
  filterModel: {},
})

const getList = async (query: Partial<PageInfo> & Partial<RepaymentModel>) => {
  // 构造查询参数
  queryParams.value.currentPage = query.page ?? 1
  queryParams.value.pageLength = query.pageSize ?? DEFAULT_PAGE_SIZE
  queryParams.value.filterModel = omit(query, ['page', 'pageSize', 'value'])
  if (Array.isArray(query.repayTime)) {
    queryParams.value.filterModel.repayTimeStart = query.repayTime[0]
    queryParams.value.filterModel.repayTimeEnd = query.repayTime[1]
    delete queryParams.value.filterModel.repayTime
  }
  const { succeed, model, total } = await creditmanageApi.getRepaymentList(queryParams.value)
  return {
    data: succeed ? model : [],
    total: total ?? 0,
  }
}

const pageConfig: PlusColumn[] = [
  {
    label: '用信编号',
    prop: 'bizSn',
    hideInSearch: false,
    order: 4,
  },
  {
    label: '还款流水号',
    prop: 'repaySn',
    hideInSearch: false,
    order: 3,
  },
  {
    label: '客户名称',
    prop: 'customerName',
  },
  {
    label: '还款期数',
    prop: 'repayPrdnum',
  },
  {
    label: '还款总金额',
    prop: 'totalAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '当期本金还款',
    prop: 'repayCurrentPrincipalAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '逾期本金还款',
    prop: 'repayOverduePrincipalAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '当期利息还款',
    prop: 'repayCurrentInterestAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '逾期利息还款',
    prop: 'repayOverdueInterestAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '还款罚息',
    prop: 'repayPenaintrAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '还款复利',
    prop: 'repayCompintrAmt',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '还款时间',
    prop: 'repayTime',
    hideInSearch: false,
    valueType: 'date-picker',
    fieldProps: {
      type: 'datetimerange',
      startPlaceholder: '开始时间',
      endPlaceholder: '结束时间',
      rangeSeparator: '至',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    order: 2,
  },
  {
    label: '客户名称',
    prop: 'customerName',
    hideInSearch: false,
    order: 1,
    hideInTable: true,
  },
  {
    label: '还款类型',
    prop: 'repayType',
    valueType: 'select',
    options: enumConfig[CommonDictEnum.YDDHKLX],
  },
]
const { buttons } = useTable()
// 按钮
buttons.value = [
  // {
  //   text: '编辑',
  //   code: 'update',
  //   props: { type: 'success' },
  // },
]
</script>
